home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / bossa.arc / BOSS_SUP.ARC / GENINDEX.C < prev    next >
C/C++ Source or Header  |  1990-03-12  |  2KB  |  75 lines

  1. /*
  2. ** GENINDEX - Create index from text file.
  3. ** 
  4. ** Support Program for The Window BOSS
  5. **
  6. ** Copyright (c) 1984,1985,1986 - Philip A. Mongelluzzo
  7. ** All rights reserved.
  8. **
  9. ** Note: The GENINDEX.EXE file was created using the CI86 compiler.
  10. **       If you attempt to recompile this program with either Lattice
  11. **       or MSC you may have to adjust the logic to account for the way
  12. **       the various compilers treat <CR><LF> sequences.  This usually
  13. **       amounts to nothing more than chaning the "rb" to "r" in the
  14. **       fopen statement.  
  15. */
  16.  
  17. #include <stdio.h>                      /* Standard stuff */
  18. #if AZTEC
  19. #define RD "r"
  20. #else
  21. #define RD "rb"
  22. #endif
  23.  
  24.  
  25. FILE *fopen();                          /* keep the compilers happy */
  26. long ftell();
  27.  
  28. main(argc,argv)
  29. int argc;
  30. char *argv[];
  31. {
  32. FILE *fp;
  33. FILE *fo;
  34. char buf[132];
  35. static char fname[132];
  36. unsigned i;
  37. long pos;
  38. char *p;
  39.  
  40.   if(argc < 2) {                        /* check command line */
  41.     printf("Usage: genindex <filename.ext>");
  42.     exit(1);
  43.   }
  44.  
  45.   p = argv[1];                          /* parse input filename */
  46.   i = 0;
  47.   while(*p) {
  48.     fname[i++] = *p++;
  49.     if(*p == ' ' || *p == '.') break;
  50.   }
  51.   strcat(fname, ".ndx");                /* create output filename */
  52.  
  53.   fp = fopen(argv[1], RD);             /* open input */
  54.   if(!fp) {
  55.     printf("Open failed: %s", argv[1]);
  56.     exit(1);
  57.   }
  58.   printf("Creating: %s\n", fname);      /* say whats going on */
  59.   fo = fopen(fname, "w");               /* open output */
  60.  
  61.   while(fgets(&buf[0],132,fp)) {        /* read lines till eof */
  62.     if(buf[0] == '%') {                 /* look for subject heading key */
  63.       fputs(buf, fo);                   /* write to index file */
  64.       fputs(buf, stdout);               /* display on console */
  65.       pos = ftell(fp);                  /* get file position */
  66.       printf("%ld\n", pos);             /* display on console */
  67.       fprintf(fo, "%ld\n", pos);        /* write in output file */
  68.     }
  69.   }
  70.   fclose(fp);                           /* close files */
  71.   fclose(fo);
  72. }
  73.  
  74. /* End */
  75.